package com.liu.lab06.service.impl;



import com.liu.lab06.mapper.MusicMapper;
import com.liu.lab06.pojo.Music;
import com.liu.lab06.service.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("musicService")
public class MusicServiceImpl implements MusicService {
    // 持有 DAO 引用，由 Spring 注入
     // ★ 需要加上这一行
    @Autowired
    private MusicMapper musicMapper;


    public void setMusicDao(MusicMapper musicMapper) {
        this.musicMapper = musicMapper;
    }

//    根据id获取音乐
    @Override
    public Music getMusicById(int id) {
        return musicMapper.findMusicById(id);
    }


//    获取所有音乐
    @Override
    public List<Music> getAllMusics() {
        return musicMapper.findAllMusics();
    }

//    根据名字搜索音乐
    @Override
    public List<Music> searchMusicsByName(String key) {
        return musicMapper.findMusicsByName(key);
    }

//    根据 音乐分类id 搜索音乐
    @Override
    public List<Music> getMusicsByCategory(int categoryId) {
        return musicMapper.findMusicsByCategory(categoryId);
    }

    @Override
    public int addMusic(Music music) {
        return musicMapper.addMusic(music);
    }

    @Override
    public int updateMusic(Music music) {
        return musicMapper.updateMusic(music);
    }

    @Override
    public int deleteMusic(int id) {
        return musicMapper.deleteMusic(id);
    }
}
